package com.c6906.vdam.das.config.redis;

import com.c6906.vdam.das.listener.ParkingKeyExpirationListener;
import com.c6906.vdam.das.service.VehicleStatusService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisListenerConfig {

    /**
     * Redis消息监听器容器，负责监听并分发Redis通知
     */
    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        return container;
    }

    /**
     * Redis key过期监听器，仅构造，无需手动注册观察者
     */
    @Bean
    public ParkingKeyExpirationListener parkingKeyExpirationListener(RedisMessageListenerContainer container, VehicleStatusService vehicleStatusService, StringRedisTemplate stringRedisTemplate) {
        return new ParkingKeyExpirationListener(container, vehicleStatusService, stringRedisTemplate);
    }
}
